import 'dart:developer';
import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 不展示右上角的debug标识
      debugShowCheckedModeBanner: false,
      title: '我的',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
            seedColor: const Color.fromARGB(255, 2, 255, 99)),
        useMaterial3: true,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  // 初始化状态
  @override
  void initState() {
    super.initState();
    // 创建TabController
    _tabController = TabController(length: 7, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 顶部导航栏
      appBar: AppBar(
        // 左侧按钮
        leading: IconButton(
          onPressed: () {
            log("导航栏左侧按钮被点击");
          },
          icon: const Icon(
            Icons.menu,
            color: Colors.white,
          ),
        ),
        // 标题
        title: const Text(
          '我的',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
          ),
        ),
        // 右侧按钮
        actions: [
          IconButton(
            onPressed: () {
              log("导航栏右侧设置按钮被点击");
            },
            icon: const Icon(
              Icons.settings,
              color: Colors.white,
            ),
          ),
          IconButton(
            onPressed: () {
              log("导航栏右侧更多按钮被点击");
            },
            icon: const Icon(
              Icons.more_horiz,
              color: Colors.white,
            ),
          ),
        ],
        backgroundColor: Colors.red, // 导航背景颜色
        bottom: TabBar(
          controller: _tabController,
          isScrollable: true, // 是否可以滚动
          // 自定义指示器
          // indicator: const BoxDecoration(
          //   color: Colors.blue,
          //   borderRadius: BorderRadius.vertical(),
          // ),
          indicatorColor: const Color.fromARGB(255, 101, 255, 109), // 指示器颜色
          indicatorPadding: const EdgeInsets.only(bottom: 3), // 指示器间距
          indicatorSize:
              TabBarIndicatorSize.label, // 指示器大小。label:和内容等宽，tab:和整个标签等宽
          labelColor: const Color.fromARGB(255, 104, 255, 197), // 选中标签颜色
          unselectedLabelColor: Colors.white, // 未选中标签颜色
          // labelStyle: ...,
          // unselectedLabelStyle: ...,
          tabs: const [
            Tab(
              child: Text("下班"),
            ),
            Tab(
              child: Text("回家"),
            ),
            Tab(
              child: Text("打游戏"),
            ),
            Tab(
              child: Text("下班"),
            ),
            Tab(
              child: Text("下班"),
            ),
            Tab(
              child: Text("下班"),
            ),
            Tab(
              child: Text("下班"),
            ),
          ],
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: const [
          Text("下班页面"),
          Text("回家页面"),
          Text("打游戏页面"),
          Text("下班页面"),
          Text("下班页面"),
          Text("下班页面"),
          Text("下班页面"),
        ],
      ),
    );
  }
}
